<template>
<el-form-item :label="labelName">
    <el-cascader v-model="landComputedPropsCode" :options="landType" :props="{ multiple: false, checkStrictly: true,value:'landTypeCode', label:'landTypeName'}"  clearable></el-cascader>
    <!-- @change="handleChange" -->
</el-form-item>
</template>

<script>
// import {
//     convertKey
// } from "@/library";
export default {
    props: {
        label: {
            type: String,
            default: function () {
                return '地块类型'
            }
        },
        landPropsCode: {
            type: [Number, String, Array],
        }
    },
    data() {
        return {
            landType: [],
            landTypeCode: []
        }
    },
    computed: {
        landComputedPropsCode: {
            get() {
                let code = []
                code.push(String(this.landPropsCode).substring(0, 2))
                code.push(String(this.landPropsCode))
                return code
            }
        },
        labelName: {
            get() {
                return this.label
            },
            set(val) {
                this.label = val
            }
        }
    },
    created() {
        this.getLandTypeList()
    },
    methods: {
        getLandTypeList() {
            this.$common.getLandType()
                .then((res) => {
                    this.landType = res.data.list
                    //  convertKey(res.data.list, {
                    //     landTypeName: "label",
                    //     landTypeCode: "value",
                    // });
                });
            console.log(this.landType);
        },
        handleChange(value) {
            console.log(value);
            this.landTypeCode = value[value.length - 1]
            this.$emit("on-change", value[value.length - 1])
        },
    },
}
</script>
